package com.seed.fileud.service;

//@Service
public class MinioFileudService {

//    @Autowired
//    private HttpServletResponse response;
//
//    @Autowired
//    private MinioService minioService;
//
//    @Override
//    public String uploadFileOrChunk(String bucket, MultipartFile file, String path, String hash) throws Exception {
//        return minioService.uploadFileOrChunk(bucket, file, path, hash);
//    }
//
//    @Override
//    public Result verify(String bucket, String path, String hash, String fileName, Integer chunkCount) throws Exception {
//        List<String> list = minioService.find(bucket, hash, fileName); //文件列表
//        if(!path.endsWith("/")) path = path + "/";
//        if(path.startsWith("/")) path = path.substring(1);
//        String ext = FileUtil.getSuffix(fileName);
//        String selfName = path + hash + (StrUtil.isBlank(ext)? "": "." + ext);
//
//        if(list.isEmpty()) {
//            List<String> chunkList = minioService.findChunkList(bucket, path, hash);
//            if(chunkList.isEmpty()) return Result.ok("文件不存在").set("status", "no");//文件不存在
//            if(chunkList.size() == chunkCount) return Result.data(chunkList).setMsg("文件全部存在,未合并").set("status", "all");
//
//            return Result.data(chunkList).setMsg("文件部分存在").set("status", "part");//文件部分存在
//        }
//
//        for (String objectName: list) {
//            if(objectName.equals(selfName)) return Result.ok("文件存在").setData(bucket + "/" + selfName).set("status", "yes");//文件存在
//        }
//
//        minioService.copyFile(list.get(0), selfName);
//        return Result.ok("文件拷贝后存在").setData(bucket + "/" + selfName).set("status", "yes");//文件拷贝后存在
//    }
//
//    @Override
//    public String merge(String bucket, String path, String hash, String fileName) throws Exception {
//        String objectName = minioService.merge(bucket, path, hash, fileName);
//        return bucket + "/" + objectName;
//    }
//
//    @Override
//    public void delete(String pathStr) throws Exception {
//        String[] paths = pathStr.split(",");
//        for(String path: paths) {
//            int pos = path.indexOf('/');
//            String bucketName = path.substring(0, pos);
//            String objectName = path.substring(pos + 1);
//            minioService.removeFile(bucketName, objectName);
//        }
//    }
//
//    @Override
//    public long getFileSize(String bucket, String objectName) throws Exception {
//        StatObjectResponse stat = minioService.getFileStatusInfo(bucket, objectName);
//        return stat.size();
//    }
//
//    @Override
//    public void downloadChunk(String bucket, String objectName, Long offset, Long length) throws Exception {
//        InputStream inputStream = minioService.getObject(bucket,objectName, offset, length);
//        ResponseUtil.download(response, inputStream);
//    }
//
//    @Override
//    public void download(String bucket, String objectName) throws Exception {
//        InputStream inputStream = minioService.getObject(bucket,objectName);
//        ResponseUtil.download(response, inputStream);
//    }
}
